package com.example.graduatetest.view.model;

import android.app.Application;
import android.util.MutableBoolean;
import android.view.View;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.graduatetest.bean.Account;
import com.example.graduatetest.callback.MCallBack;
import com.example.graduatetest.databinding.ActivityMainBinding;
import com.example.graduatetest.model.TestModel;


public class TestViewModel extends ViewModel {
    private TestModel model;

    private MutableLiveData<Integer> number;
    private MutableLiveData<String> result;
    private MutableLiveData<String> userInput;

    public void init(Application application){
        model = new TestModel();
    }

    public void getData(){

        model.getAccountData(userInput.getValue(), new MCallBack() {
            @Override
            public void onSuccess(Account account) {
                String info = account.getName() + "|" + account.getLevel();
                result.setValue(info);
            }

            @Override
            public void onFailed() {
                result.setValue("获取失败");
            }
        });
    }


    public MutableLiveData<String> getResult() {
        if(result == null){
            result = new MutableLiveData<>();
            result.setValue("暂无查询");
        }
        return result;
    }



    public MutableLiveData<String> getUserInput() {
        if(userInput == null){
            userInput = new MutableLiveData<>();
        }
        return userInput;
    }



    public MutableLiveData<Integer> getNumber() {
        if(number == null){
            number = new MutableLiveData<>();
            number.setValue(0);
        }
        return number;
    }
    public void add(){
        number.setValue(number.getValue()+1);
    }
}
